﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BSCMFF.Core.DataAccessLayer;

namespace BSCMFF.Core.BusinessLayer
{
    public class DepartmentManager
    {
        public bool DepartmentExists(string departmentName)
        {
            BSCEntities context = new BSCEntities();

            List<SBU> departments = (from sbu in context.SBUs
                                     select sbu).ToList();
            foreach (SBU d in departments)
            {
                if (d.Name == departmentName)
                {
                    return true;
                }                
            }
            return false;
        }

        public int GetDepartmentID(string departmentName)
        {
            BSCEntities context = new BSCEntities();

            SBU department = (from sbu in context.SBUs
                                where sbu.Name == departmentName
                                select sbu).Single();
            return department.SBU_ID;
        }

        public SBU GetDepartmentByID(int sbu_ID)
        {
            BSCEntities context = new BSCEntities();

            SBU department = (from sbu in context.SBUs
                              where sbu.SBU_ID == sbu_ID
                              select sbu).SingleOrDefault();
            return department;
        }
    }
}
